/**
 @file ctc_learning_aging_cli.c

 @date 2010-3-1

 @version v2.0

*/

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/

#include "sal.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_learning_aging_cli.h"
#include "ctcs_api.h"
#include "ctc_learning_aging.h"
#include "ctc_error.h"
#include "ctc_debug.h"



CTC_CLI(ctc_cli_asw_learning_aging_set_aging_property,
        ctc_cli_asw_learning_aging_set_aging_property_cmd,
        "aging ({ interval INTERVAL } | { fifo-scan (enable | disable) })",
        CTC_CLI_AGING_STR,
        "Aging interval",
        "Aging interval(unit: seconds)",
        "Aging fifo scan",
        "Open aging fifo scan",
        "Close aging fifo scan")
{
    ctc_aging_prop_t type = CTC_AGING_PROP_MAX;
    uint32 value = 0;
    int32 ret = 0;
    ctc_aging_table_type_t  tbl_type = CTC_AGING_TBL_MAC;

    uint32 index;
    index = CTC_CLI_GET_ARGC_INDEX("interval");
    if (0xFF != index)
    {
        type = CTC_AGING_PROP_INTERVAL;
        if (argc <= (index + 1))
        {
            ctc_cli_out("%% Insufficient  param \n\r");
            return CLI_ERROR;
        }

        CTC_CLI_GET_UINT32_RANGE("Aging interval(unit: seconds)", value, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("fifo-scan");
    if (0xFF != index)
    {
        type = CTC_AGING_PROP_AGING_SCAN_EN;
        if (argc <= (index + 1))
        {
            ctc_cli_out("%% Insufficient  param \n\r");
            return CLI_ERROR;
        }

        if (0 == sal_memcmp("enable", argv[index + 1], 6))
        {
            value = 1;
        }
        else if (0 == sal_memcmp("disable", argv[index + 1], 7))
        {
            value = 0;
        }
    }

    ret = ctcs_aging_set_property(g_api_lchip, tbl_type, type, value);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;

}

CTC_CLI(ctc_cli_asw_learning_aging_show_config,
        ctc_cli_asw_learning_aging_show_config_cmd,
        "show aging config",
        CTC_CLI_SHOW_STR,
        CTC_CLI_AGING_STR,
        "Config param"
        )
{
    uint32 value32 = 0;
    int32  ret = 0;
    ctc_aging_table_type_t  tbl_type = CTC_AGING_TBL_MAC;

    ret = ctcs_aging_get_property(g_api_lchip, tbl_type, CTC_AGING_PROP_INTERVAL, &value32);


    ctc_cli_out("aging_interval:%d \n", value32);


    ret = ret?ret:ctcs_aging_get_property(g_api_lchip, tbl_type, CTC_AGING_PROP_AGING_SCAN_EN, &value32);

    ctc_cli_out("aging_scan_en:%s\n", (value32 == TRUE) ? "TRUE" : "FALSE");

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


int32
ctc_asw_learning_aging_cli_init(uint8 cli_tree_mode)
{
    install_element(cli_tree_mode, &ctc_cli_asw_learning_aging_set_aging_property_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_learning_aging_show_config_cmd);
    return CLI_SUCCESS;
}

